package cn.cdu.data.controller;

import cn.cdu.basics.service.UserService;
import cn.cdu.data.entity.AddUser;
import cn.cdu.data.entity.User;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Map;


@RestController
@Tag(name = "管理员接口")
@RequestMapping("/zwz/admin")
@CacheConfig(cacheNames = "admin")
@Transactional

public class AdminController {

    @Resource
    private UserService userService;
    @GetMapping ("/delById")
    @Operation(summary = "删除用户数据")
    public String delById(String id) {
        if(userService.delById(id)){
            return "成功";
        }
        return "失败";
    }

    @GetMapping ("/resetPass")
    @Operation(summary = "重置用户密码")
    public String resetPass(String id) {
        if(userService.resetPass(id)){
            return "成功";
        }
        return "失败";
    }


    @GetMapping ("/enable")
    @Operation(summary = "启用用户")
    public String enable(String id) {
        if(userService.enable(id)){
            return "成功";
        }
        return "失败";
    }


    @GetMapping ("/disable")
    @Operation(summary = "禁用用户")
    public String disable(String id) {
        if(userService.disable(id)){
            return "成功";
        }
        return "失败";
    }

    @PostMapping("/add")
    @Operation(summary = "添加用户")
    public String add(@RequestBody AddUser user){
        if(userService.add(user)){
            return "成功";
        }
        return "失败";

    }
    @PostMapping("/edit")
    @Operation(summary = "编辑用户")
    public String edit(@RequestBody User user){
        if(userService.edit(user)){
            return "成功";
        }
        return "失败";

    }
    @GetMapping ("/delRoleById")
    @Operation(summary = "删除角色数据")
    public String delRoleById(String id) {
        if(userService.delRoleById(id)){
            return "成功";
        }
        return "失败";
    }


    @GetMapping ("/cancelDefault")
    @Operation(summary = "设为默认角色")
    public String cancelDefault(String id) {
        if(userService.cancelDefault(id)){
            return "成功";
        }
        return "失败";
    }


    @GetMapping ("/setDefault")
    @Operation(summary = "取消默认角色")
    public String setDefault(String id) {
        if(userService.setDefault(id)){
            return "成功";
        }
        return "失败";
    }

}
